package servlet;

import db.DB;
import model.*;
import java.sql.Date;
import java.io.IOException;
//import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AddServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("gb2312");
		
		response.setContentType("text/html");
		
		String title=request.getParameter("title");
		
		String content=request.getParameter("content");
		
		User user=(User)request.getSession().getAttribute("user");
		
		MessageTable mt=new MessageTable();
		mt.setUserId(user.getId());
		mt.setDate(new Date(System.currentTimeMillis()));
		mt.setTitle(title);
		mt.setContent(content);
		if(new DB().addInfo(mt)){
			response.sendRedirect("success.jsp");
		}
		
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}
